/**
 * created the 4 oct. 07
 */
package choco.global.scheduling.trees.abstrees;

import choco.integer.IntDomainVar;

/**
 * This class complete the Theta-tree structure to apply edge finding rules.
 *  all applicable activities i will be also included in the tree, but as gray nodes. A gray node represents an activity i which is not really in the set Theta.
 * However, we are curious what would happen with ECT_{Theta} if we are allowed to include <b>one</b> of the gray activities into the set Theta.
 * It uses additionnal fields to compute gray values.
 * @author Arnaud Malapert (arnaud.malapert@emn.fr)
 *
 */
public abstract class AbstractThetaLambdaTree extends AbstractTree {

	/**
	 * @param vars 
	 * @param processingTimes
	 */
	public AbstractThetaLambdaTree(IntDomainVar[] vars, int[] processingTimes,
			boolean ectOrLst) {
		super(vars, processingTimes, ectOrLst);
	}

	
	/**
	 * @param vars
	 * @param processingTimes
	 * @param ectOrLst
	 */
	public AbstractThetaLambdaTree(IntDomainVar[] vars, long[] processingTimes, boolean ectOrLst) {
		super(vars, processingTimes, ectOrLst);
	}


	/**
	 * @see choco.global.scheduling.trees.abstrees.AbstractTree#resetColor()
	 */
	@Override
	protected int resetColor() {
		return Leaf.WHITE;

	}

	/**
	 * remove the task of theta subset and insert it in lambda subset 
	 * @param task the task to remove
	 * @return <code>true</code> if successfull
	 */
	public final boolean rmThetaAndInsertLambda(int task) {
		Leaf leaf=this.getLeaf(task);
		if(leaf.getColor()== Leaf.WHITE) {
			leaf.infos.update(leaf,this.ectOrLst);
			leaf.setColor(Leaf.GRAY);
			if(leaf.hasFather()) {leaf.getFather().update(this.ectOrLst);}
			return true;
		}
		return false;
	}
	
	/**
	 * remove the task of lambda subset. you must have already called {@link AbstractThetaLambdaTree#rmThetaAndInsertLambda(int)} on the task. 
	 * @param task the task to remove
	 * @return <code>true</code> if successfull
	 */
	public final boolean rmLambda(int task) {
		Leaf leaf=this.getLeaf(task);
		if(leaf.getColor()== Leaf.GRAY) {
			leaf.infos.update(leaf,this.ectOrLst);
			leaf.setColor(Leaf.BLACK);
			if(leaf.hasFather()) {leaf.getFather().update(this.ectOrLst);}
			return true;
		}
		return false;
	}
}
